const DB = wx.cloud.database().collection('note_list');
const util = require("../../utils/util.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    title: "详情",
    isTransform: false,
    isBack: true,
    modify: true
  },

  onLoad: function (options) {
    console.log(options);
    this.setData({
      nodedetail: options
    })
  },

  modify() {
    let that = this;
    that.setData({
      modify: false
    })
  },
  delete() {
    let that = this;
    wx.showModal({
      cancelColor: 'cancelColor',
      title: '确认删除？',
      success: function (res) {
        if (res.confirm) {
          DB.doc(that.data.nodedetail.id).remove().then(res => {
            console.log(res);
            wx.showToast({
              title: '删除成功',
              icon: 'success'
            })
            wx.navigateBack({
              delta: 1,
            })
          })
        }else{
        
        }
      } 
    })

  },
  formSubmit: function (e) {
    let date = {
      date: util.formatDate(new Date())[0],
      time: util.formatDate(new Date())[1],
    }
    let all = util.extend(date, e.detail.value)
    console.log(all);
    if (e.detail.value.thing == "") {
      wx.showToast({
        title: '请输入标题',
        icon: 'none'
      })
    } else if (e.detail.value.context == "") {
      wx.showToast({
        title: '请输入详细内容',
        icon: 'none'
      })
    } else {
      DB.doc(this.data.nodedetail.id).update({
        data: all,
        success: res => {
          wx.showToast({
            title: '修改成功',
            icon: 'success'
          })
          wx.navigateBack({
            delta: 1,
          })
        },
        fail: res => {
          console.log("失败", res);
        }
      })
    }
  },

})